home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / vectors / qtvectors / application files / comapplication.c next >
Encoding:
Text File  |  2000-06-23  |  9.7 KB  |  404 lines

  1. //////////
  2. //
  3. //    File:        ComApplication.c
  4. //
  5. //    Contains:    Application-specific code for basic movie display and control.
  6. //                This file is used for BOTH MacOS and Windows.
  7. //
  8. //    Written by:    Tim Monroe
  9. //                Based (heavily!) on the MovieShell code written by Apple DTS.
  10. //
  11. //    Copyright:    © 1994-1997 by Apple Computer, Inc., all rights reserved.
  12. //
  13. //    Change History (most recent first):
  14. //
  15. //       <11>         12/16/98    rtm        removed all QTVR API calls, so we can remove QTVR.lib from project
  16. //       <10>         10/23/97    rtm        moved InitializeQTVR to InitApplication, TerminateQTVR to StopApplication
  17. //       <9>         10/13/97    rtm        reworked HandleApplicationMenu to use menu identifiers
  18. //       <8>         09/11/97    rtm        merged MacApplication.c and WinApplication.c into ComApplication.c
  19. //       <7>         08/21/97    rtm        first file for Windows; based on MacApplication.c for Mac sample code
  20. //       <6>         06/04/97    rtm        removed call to QTVRUtils_IsQTVRMovie in InitApplicationWindowObject
  21. //       <5>         02/06/97    rtm        fixed window resizing code
  22. //       <4>         12/05/96    rtm        added hooks into MacFramework.c: StopApplication, InitApplicationWindowObject
  23. //       <3>         12/02/96    rtm        added cursor updating to DoIdle
  24. //       <2>         11/27/96    rtm        conversion to personal coding style; added preliminary QTVR support
  25. //       <1>         12/21/94    khs        first file
  26. //       
  27. //////////
  28.  
  29. // header files
  30. #include "ComApplication.h"
  31. #include "QTVectors.h"
  32.  
  33. // global variables for Macintosh code
  34. #if TARGET_OS_MAC
  35. #endif
  36.  
  37. // global variables for Windows code
  38. #if TARGET_OS_WIN32
  39. extern HWND                ghWnd;                                    // the MDI frame window; this window has the menu bar
  40. extern int                gNumWindowsOpen;
  41. extern LPSTR            gCmdLine;
  42. #endif
  43.  
  44. long                    gMaxMilliSecToUse = 0L;        
  45.  
  46.  
  47. //////////
  48. //
  49. // InitApplication
  50. // Do any application-specific initialization.
  51. //
  52. // The theStartPhase parameter determines which "phase" of application start-up is executed,
  53. // *before* the MDI frame window is created or *after*. This distinction is relevant only on
  54. // Windows, so on MacOS, you should always use kInitAppPhase_BothPhases.
  55. //
  56. //////////
  57.  
  58. void InitApplication (UInt32 theStartPhase)
  59. {
  60.     // ***do any start-up activities that should occur before the MDI frame window is created
  61.     if (theStartPhase & kInitAppPhase_BeforeCreateFrameWindow) {
  62.  
  63.     }    // end of kInitAppPhase_BeforeCreateFrameWindow
  64.  
  65.     // ***do any start-up activities that should occur after the MDI frame window is created
  66.     if (theStartPhase & kInitAppPhase_AfterCreateFrameWindow) {
  67.         
  68. #if TARGET_OS_WIN32
  69.         // on Windows, open as movie documents any files specified on the command line
  70.         DoOpenCommandLineMovies(gCmdLine);                                    
  71. #endif
  72.  
  73.     }    // end of kInitAppPhase_AfterCreateFrameWindow
  74. }
  75.  
  76.  
  77. //////////
  78. //
  79. // StopApplication
  80. // Do any application-specific shut-down.
  81. //
  82. // The theStopPhase parameter determines which "phase" of application shut-down is executed,
  83. // *before* any open movie windows are destroyed or *after*.
  84. //
  85. //////////
  86.  
  87. void StopApplication (UInt32 theStopPhase)
  88. {
  89.  
  90. }
  91.  
  92.  
  93. //////////
  94. //
  95. // DoIdle
  96. // Do any processing that can/should occur at idle time.
  97. //
  98. //////////
  99.  
  100. void DoIdle (WindowReference theWindow)
  101. {
  102.     WindowObject         myWindowObject = NULL;
  103.     GrafPtr             mySavedPort;
  104.     
  105.     GetPort(&mySavedPort);
  106.     MacSetPort(GetPortFromWindowReference(theWindow));
  107.     
  108.     myWindowObject = GetWindowObjectFromWindow(theWindow);
  109.     if (myWindowObject != NULL) {
  110.         MovieController        myMC = NULL;
  111.     
  112.         myMC = (**myWindowObject).fController;
  113.         if (myMC != NULL) {
  114.  
  115. #if TARGET_OS_MAC
  116.             // restore the cursor to the arrow
  117.             // if it's outside the front movie window or outside the window's visible region
  118.             if (theWindow == GetFrontMovieWindow()) {
  119.                 Rect    myRect;
  120.                 Point    myPoint;
  121.                 
  122.                 GetMouse(&myPoint);
  123.                 MCGetControllerBoundsRect(myMC, &myRect);
  124.                 if (!MacPtInRect(myPoint, &myRect) || !PtInRgn(myPoint, GetPortFromWindowReference(theWindow)->visRgn))
  125.                     MacSetCursor(&qd.arrow);
  126.             }
  127. #endif    // TARGET_OS_MAC
  128.         }
  129.     }
  130.     
  131.     // @@@INSERT APPLICATION-SPECIFIC IDLE-TIME FUNCTIONALITY HERE
  132.     
  133.     MacSetPort(mySavedPort);
  134. }
  135.  
  136.  
  137. //////////
  138. //
  139. // DoUpdateWindow
  140. // Update the specified window.
  141. //
  142. //////////
  143.  
  144. void DoUpdateWindow (WindowReference theWindow, Rect *theRefreshArea)
  145. {
  146.     GrafPtr             mySavedPort;
  147.     
  148.     GetPort(&mySavedPort);
  149.     MacSetPort(GetPortFromWindowReference(theWindow));
  150.     
  151.     BeginUpdate(GetPortFromWindowReference(theWindow));
  152.     
  153.     // draw the movie controller and its movie
  154.     MCDoAction(GetMCFromWindow(theWindow), mcActionDraw, theWindow);
  155.     
  156.     EndUpdate(GetPortFromWindowReference(theWindow));
  157.     MacSetPort(mySavedPort);
  158. }
  159.  
  160.  
  161. //////////
  162. //
  163. // HandleContentClick
  164. // Handle mouse button clicks in the specified window.
  165. //
  166. //////////
  167.  
  168. void HandleContentClick (WindowReference theWindow, EventRecord *theEvent)
  169. {
  170.     GrafPtr             mySavedPort;
  171.     
  172.     GetPort(&mySavedPort);
  173.     MacSetPort(GetPortFromWindowReference(theWindow));
  174.     
  175.     // @@@INSERT APPLICATION-SPECIFIC CONTENT CLICKING FUNCTIONALITY HERE
  176.  
  177.     MacSetPort(mySavedPort);
  178. }
  179.  
  180.  
  181. //////////
  182. //
  183. // HandleApplicationKeyPress
  184. // Handle application-specific key presses.
  185. // Returns true if the key press was handled, false otherwise.
  186. //
  187. //////////
  188.  
  189. Boolean HandleApplicationKeyPress (char theCharCode)
  190. {
  191.     Boolean        isHandled = true;
  192.     
  193.     switch (theCharCode) {
  194.     
  195.         // @@@HANDLE APPLICATION-SPECIFIC KEY PRESSES HERE
  196.  
  197.         default:
  198.             isHandled = false;
  199.             break;
  200.     }
  201.  
  202.     return(isHandled);
  203. }
  204.  
  205.  
  206. #if TARGET_OS_MAC
  207. //////////
  208. //
  209. // CreateMovieWindow
  210. // Create a window to display a movie in.
  211. //
  212. //////////
  213.  
  214. WindowRef CreateMovieWindow (Rect *theRect, Str255 theTitle)
  215. {
  216.     WindowRef            myWindow;
  217.         
  218.     myWindow = NewCWindow(NULL, theRect, theTitle, false, noGrowDocProc, (WindowPtr)-1L, true, 0);
  219.     return(myWindow);
  220. }
  221. #endif
  222.  
  223.  
  224. //////////
  225. //
  226. // HandleApplicationMenu
  227. // Handle selections in the application's menus.
  228. //
  229. // The theMenuItem parameter is a UInt16 version of the Windows "menu item identifier". 
  230. // When called from Windows, theMenuItem is simply the menu item identifier passed to the window proc.
  231. // When called from MacOS, theMenuItem is constructed like this:
  232. //     *high-order 8 bits == the Macintosh menu ID (1 thru 256)
  233. //     *low-order 8 bits == the Macintosh menu item (sequential from 1 to ordinal of last menu item in menu)
  234. // In this way, we can simplify the menu-handling code. There are, however, some limitations,
  235. // mainly that the menu item identifiers on Windows must be derived from the Mac values. 
  236. //
  237. //////////
  238.  
  239. void HandleApplicationMenu (UInt16 theMenuItem)
  240. {
  241.     WindowObject        myWindowObject = NULL;
  242.     MovieController     myMC = NULL;
  243.     
  244.     switch (theMenuItem) {
  245.     
  246.         case IDM_CREATE_VECTOR_MOVIE_RAW:
  247.             QTVectors_CreateVectorMovie(kUseRawDataStream);
  248.             break;
  249.         
  250.         case IDM_CREATE_VECTOR_MOVIE_UTIL:
  251.             QTVectors_CreateVectorMovie(kUseCurveUtilities);
  252.             break;
  253.         
  254.         default:
  255.             break;
  256.     }    // switch (theMenuItem)
  257. }
  258.  
  259.  
  260. //////////
  261. //
  262. // AdjustApplicationMenus
  263. // Adjust state of items in the application's menus.
  264. //
  265. //////////
  266.  
  267. void AdjustApplicationMenus (WindowReference theWindow, MenuReference theMenu)
  268. {
  269.     WindowObject        myWindowObject = NULL; 
  270.     MovieController     myMC = NULL;
  271.     MenuReference            myMenu;
  272.     
  273. #if TARGET_OS_WIN32
  274.     myMenu = theMenu;
  275. #elif TARGET_OS_MAC
  276.     myMenu = GetMenuHandle(kTestMenu);
  277. #endif
  278.     
  279.     if (theWindow != NULL)
  280.         myWindowObject = GetWindowObjectFromWindow(theWindow);
  281.  
  282.     if (myWindowObject != NULL)
  283.         myMC = (**myWindowObject).fController;
  284.  
  285.     // we don't allow creating new files here...
  286. #if TARGET_OS_MAC
  287.     SetMenuItemState(GetMenuHandle(mFile), iNew, kDisableMenuItem);
  288. #endif
  289.  
  290.     SetMenuItemState(myMenu, IDM_CREATE_VECTOR_MOVIE_RAW, kEnableMenuItem);
  291.     SetMenuItemState(myMenu, IDM_CREATE_VECTOR_MOVIE_UTIL, kEnableMenuItem);
  292. }
  293.  
  294.  
  295. //////////
  296. //
  297. // DoApplicationEventLoopAction
  298. // Perform any application-specific event loop actions.
  299. //
  300. // Return true to indicate that we've completely handled the event here, false otherwise.
  301. //
  302. //////////
  303.  
  304. Boolean DoApplicationEventLoopAction (EventRecord *theEvent)
  305. {
  306.     return(false);            // no-op for now
  307. }
  308.  
  309.  
  310. //////////
  311. //
  312. // AddControllerFunctionality
  313. // Configure the movie controller.
  314. //
  315. //////////
  316.  
  317. void AddControllerFunctionality (MovieController theMC)
  318. {
  319.     long            myControllerFlags;
  320.     
  321.     // CLUT table use    
  322.     MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
  323.     MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags | mcFlagsUseWindowPalette));
  324.  
  325.     // enable keyboard event handling    
  326.     MCDoAction(theMC, mcActionSetKeysEnabled, (void *)true);
  327.     
  328.     // disable drag support
  329.     MCDoAction(theMC, mcActionSetDragEnabled, (void *)false);
  330. }
  331.  
  332.  
  333. //////////
  334. //
  335. // InitApplicationWindowObject
  336. // Do any application-specific initialization of the window object.
  337. //
  338. //////////
  339.  
  340. void InitApplicationWindowObject (WindowObject theWindowObject)
  341. {
  342.     // @@@INSERT APPLICATION-SPECIFIC WINDOW OBJECT INITIALIZATION HERE
  343. }
  344.  
  345.  
  346. //////////
  347. //
  348. // RemoveApplicationWindowObject
  349. // Do any application-specific clean-up of the window object.
  350. //
  351. //////////
  352.  
  353. void RemoveApplicationWindowObject (WindowObject theWindowObject)
  354. {
  355.     
  356.     // @@@INSERT APPLICATION-SPECIFIC WINDOW OBJECT CLEAN-UP HERE
  357.  
  358.     // DoDestroyMovieWindow in MacFramework.c or MovieWndProc in WinFramework.c
  359.     // releases the window object itself
  360. }
  361.  
  362.  
  363. //////////
  364. //
  365. // ApplicationMCActionFilterProc 
  366. // Intercept some mc actions for the movie controller.
  367. //
  368. // NOTE: The theRefCon parameter is a handle to a window object record.
  369. //
  370. //////////
  371.  
  372. PASCAL_RTN Boolean ApplicationMCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon)
  373. {
  374. #pragma unused(theMC, theParams)
  375.  
  376.     Boolean                isHandled = false;
  377.     WindowObject        myWindowObject = NULL;
  378.     
  379.     myWindowObject = (WindowObject)theRefCon;
  380.     if (myWindowObject == NULL)
  381.         return(isHandled);
  382.         
  383.     switch (theAction) {
  384.     
  385.         // handle window resizing
  386.         case mcActionControllerSizeChanged:
  387.             SizeWindowToMovie(myWindowObject);
  388.             break;
  389.  
  390.         // handle idle events
  391.         case mcActionIdle:
  392.             DoIdle((**myWindowObject).fWindow);
  393.             break;
  394.             
  395.         default:
  396.             break;
  397.             
  398.     }    // switch (theAction)
  399.     
  400.     return(isHandled);    
  401. }
  402.  
  403.  
  404.